package io.renren.modules.project.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.project.service.ProjectManageService;
import io.renren.modules.project.vo.ProjectVoEntity;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * 项目管理
 *
 * @author ygg
 * @date 2019-11-01 16:46:10
 */
@RestController
@RequestMapping("project/manage")
public class ProjectManageController {
    @Autowired
    public ProjectManageService projectManageService;

    /**
     * 列表
     */
//    @SysLog("查看项目管理")
    @RequestMapping("/page")
    @RequiresPermissions("project:manage:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = projectManageService.getProjectManagPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 导出项目列表
     */
    @SysLog("导出项目管理列表")
    @RequestMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        try {
            Workbook workbook = projectManageService.exportProExcel(params);

            //准备将Excel的输出流通过response输出到页面下载
            response.setContentType("application/vnd.ms-excel");
            //设置导出Excel的名称
            response.setHeader("Content-disposition", "attachment;filename= 1.xls");
            //刷新缓冲
            response.flushBuffer();
            //workbook将Excel写入到response的输出流中，供页面下载该Excel文件
            workbook.write(response.getOutputStream());
            //关闭workbook
            workbook.close();
        } catch (Exception ex){
            ;
        }
    }
}
